﻿namespace WinForms.ControlList.LeadFrom
{
    using Bll.Company;
    using Bll.Procurement;
    using Bll.Stock;
    using Bll.Supplier;
    using Model.Company;
    using Model.Procurement;
    using Model.Supplier;
    using Model.Systems;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    using WinForms;
    using WinForms.ControlList.Procurement;
    using WinForms.Properties;

    public class FrmProLead : Form
    {
        private Button btn_Close;
        private IContainer components = null;
        public const int HTCAPTION = 2;
        private Label lblTitle;
        private LinkLabel link_caigou;
        private LinkLabel link_caigoufukuan;
        private int newProId = 0;
        private Panel pan_AllPanel;
        private Panel pan_AllPlanes;
        private Panel pan_Bottoms;
        private Panel pan_Dock;
        private Panel pan_DockBottom;
        private Panel pan_DockLeft;
        private Panel pan_DockRight;
        private Panel pan_Lefts;
        private Panel pan_Rights;
        private Panel pan_Top;
        private Panel pan_TopLeft;
        private Panel pan_TopRight;
        private Panel pan_ZhongJian;
        private Panel pan_采购;
        private Panel pane_TopT;
        private Panel panel_Button;
        private Panel panel2;
        private Panel panel9;
        private PictureBox pic_caigou;
        private PictureBox pic_fukuan;
        private PictureBox pic_right;
        public const int SC_MOVE = 0xf010;
        public const int WM_SYSCOMMAND = 0x112;

        public FrmProLead()
        {
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.pan_DockLeft = new Panel();
            this.pan_Dock = new Panel();
            this.pan_AllPanel = new Panel();
            this.pan_AllPlanes = new Panel();
            this.panel_Button = new Panel();
            this.btn_Close = new Button();
            this.panel2 = new Panel();
            this.link_caigoufukuan = new LinkLabel();
            this.pic_fukuan = new PictureBox();
            this.pan_采购 = new Panel();
            this.pic_caigou = new PictureBox();
            this.link_caigou = new LinkLabel();
            this.pic_right = new PictureBox();
            this.panel9 = new Panel();
            this.pan_Rights = new Panel();
            this.pan_Lefts = new Panel();
            this.pan_Bottoms = new Panel();
            this.pane_TopT = new Panel();
            this.pan_DockBottom = new Panel();
            this.pan_DockRight = new Panel();
            this.pan_Top = new Panel();
            this.pan_ZhongJian = new Panel();
            this.lblTitle = new Label();
            this.pan_TopRight = new Panel();
            this.pan_TopLeft = new Panel();
            this.pan_Dock.SuspendLayout();
            this.pan_AllPanel.SuspendLayout();
            this.pan_AllPlanes.SuspendLayout();
            this.panel_Button.SuspendLayout();
            this.panel2.SuspendLayout();
            ((ISupportInitialize) this.pic_fukuan).BeginInit();
            this.pan_采购.SuspendLayout();
            ((ISupportInitialize) this.pic_caigou).BeginInit();
            ((ISupportInitialize) this.pic_right).BeginInit();
            this.pan_Top.SuspendLayout();
            this.pan_ZhongJian.SuspendLayout();
            base.SuspendLayout();
            this.pan_DockLeft.BackColor = Color.FromArgb(0xaf, 0xbf, 190);
            this.pan_DockLeft.Dock = DockStyle.Left;
            this.pan_DockLeft.Location = new Point(0, 0);
            this.pan_DockLeft.Name = "pan_DockLeft";
            this.pan_DockLeft.Size = new Size(1, 0xde);
            this.pan_DockLeft.TabIndex = 0;
            this.pan_Dock.BackColor = Color.FromArgb(0, 0, 15, 0xff);
            this.pan_Dock.Controls.Add(this.pan_AllPanel);
            this.pan_Dock.Controls.Add(this.pan_DockBottom);
            this.pan_Dock.Controls.Add(this.pan_DockRight);
            this.pan_Dock.Controls.Add(this.pan_DockLeft);
            this.pan_Dock.Dock = DockStyle.Fill;
            this.pan_Dock.Location = new Point(0, 0x20);
            this.pan_Dock.Name = "pan_Dock";
            this.pan_Dock.Size = new Size(0x171, 0xde);
            this.pan_Dock.TabIndex = 5;
            this.pan_AllPanel.BackColor = Color.White;
            this.pan_AllPanel.Controls.Add(this.pan_AllPlanes);
            this.pan_AllPanel.Controls.Add(this.pan_Rights);
            this.pan_AllPanel.Controls.Add(this.pan_Lefts);
            this.pan_AllPanel.Controls.Add(this.pan_Bottoms);
            this.pan_AllPanel.Controls.Add(this.pane_TopT);
            this.pan_AllPanel.Dock = DockStyle.Fill;
            this.pan_AllPanel.Location = new Point(1, 0);
            this.pan_AllPanel.Name = "pan_AllPanel";
            this.pan_AllPanel.Size = new Size(0x16f, 0xdd);
            this.pan_AllPanel.TabIndex = 3;
            this.pan_AllPlanes.Controls.Add(this.panel_Button);
            this.pan_AllPlanes.Controls.Add(this.panel2);
            this.pan_AllPlanes.Controls.Add(this.pan_采购);
            this.pan_AllPlanes.Controls.Add(this.pic_right);
            this.pan_AllPlanes.Controls.Add(this.panel9);
            this.pan_AllPlanes.Dock = DockStyle.Fill;
            this.pan_AllPlanes.Location = new Point(10, 10);
            this.pan_AllPlanes.Name = "pan_AllPlanes";
            this.pan_AllPlanes.Size = new Size(0x15b, 0xc9);
            this.pan_AllPlanes.TabIndex = 4;
            this.panel_Button.Controls.Add(this.btn_Close);
            this.panel_Button.Dock = DockStyle.Bottom;
            this.panel_Button.Location = new Point(0, 0x99);
            this.panel_Button.Name = "panel_Button";
            this.panel_Button.Size = new Size(0x15b, 0x2b);
            this.panel_Button.TabIndex = 11;
            this.panel_Button.Paint += new PaintEventHandler(this.panel_Button_Paint);
            this.btn_Close.Location = new Point(0x88, 10);
            this.btn_Close.Name = "btn_Close";
            this.btn_Close.Size = new Size(0x4b, 0x17);
            this.btn_Close.TabIndex = 6;
            this.btn_Close.Text = "关 闭";
            this.btn_Close.UseVisualStyleBackColor = true;
            this.panel2.Controls.Add(this.link_caigoufukuan);
            this.panel2.Controls.Add(this.pic_fukuan);
            this.panel2.Location = new Point(210, 0x21);
            this.panel2.Name = "panel2";
            this.panel2.Size = new Size(0x40, 0x5d);
            this.panel2.TabIndex = 10;
            this.link_caigoufukuan.AutoSize = true;
            this.link_caigoufukuan.Location = new Point(6, 0x49);
            this.link_caigoufukuan.Name = "link_caigoufukuan";
            this.link_caigoufukuan.Size = new Size(0x35, 12);
            this.link_caigoufukuan.TabIndex = 10;
            this.link_caigoufukuan.TabStop = true;
            this.link_caigoufukuan.Text = "采购付款";
            this.link_caigoufukuan.LinkClicked += new LinkLabelLinkClickedEventHandler(this.link_caigoufukuan_LinkClicked);
            this.pic_fukuan.Dock = DockStyle.Top;
            this.pic_fukuan.Image = Resources.fyzc;
            this.pic_fukuan.Location = new Point(0, 0);
            this.pic_fukuan.Name = "pic_fukuan";
            this.pic_fukuan.Size = new Size(0x40, 0x40);
            this.pic_fukuan.SizeMode = PictureBoxSizeMode.AutoSize;
            this.pic_fukuan.TabIndex = 9;
            this.pic_fukuan.TabStop = false;
            this.pic_fukuan.Click += new EventHandler(this.pic_fukuan_Click);
            this.pan_采购.Controls.Add(this.pic_caigou);
            this.pan_采购.Controls.Add(this.link_caigou);
            this.pan_采购.Location = new Point(0x49, 0x21);
            this.pan_采购.Name = "pan_采购";
            this.pan_采购.Size = new Size(0x40, 0x5d);
            this.pan_采购.TabIndex = 7;
            this.pic_caigou.Dock = DockStyle.Top;
            this.pic_caigou.Image = Resources.gh;
            this.pic_caigou.Location = new Point(0, 0);
            this.pic_caigou.Name = "pic_caigou";
            this.pic_caigou.Size = new Size(0x40, 0x40);
            this.pic_caigou.SizeMode = PictureBoxSizeMode.AutoSize;
            this.pic_caigou.TabIndex = 4;
            this.pic_caigou.TabStop = false;
            this.pic_caigou.Click += new EventHandler(this.pic_caigou_Click);
            this.link_caigou.AutoSize = true;
            this.link_caigou.Location = new Point(6, 0x49);
            this.link_caigou.Name = "link_caigou";
            this.link_caigou.Size = new Size(0x35, 12);
            this.link_caigou.TabIndex = 6;
            this.link_caigou.TabStop = true;
            this.link_caigou.Text = "采购茶叶";
            this.link_caigou.LinkClicked += new LinkLabelLinkClickedEventHandler(this.link_caigou_LinkClicked);
            this.pic_right.Image = Resources.arrowhead_right;
            this.pic_right.Location = new Point(0x9f, 0x3f);
            this.pic_right.Name = "pic_right";
            this.pic_right.Size = new Size(0x1d, 0x19);
            this.pic_right.SizeMode = PictureBoxSizeMode.AutoSize;
            this.pic_right.TabIndex = 5;
            this.pic_right.TabStop = false;
            this.panel9.Dock = DockStyle.Bottom;
            this.panel9.Location = new Point(0, 0xc4);
            this.panel9.Name = "panel9";
            this.panel9.Size = new Size(0x15b, 5);
            this.panel9.TabIndex = 3;
            this.pan_Rights.Dock = DockStyle.Right;
            this.pan_Rights.Location = new Point(0x165, 10);
            this.pan_Rights.Name = "pan_Rights";
            this.pan_Rights.Size = new Size(10, 0xc9);
            this.pan_Rights.TabIndex = 3;
            this.pan_Lefts.Dock = DockStyle.Left;
            this.pan_Lefts.Location = new Point(0, 10);
            this.pan_Lefts.Name = "pan_Lefts";
            this.pan_Lefts.Size = new Size(10, 0xc9);
            this.pan_Lefts.TabIndex = 2;
            this.pan_Bottoms.Dock = DockStyle.Bottom;
            this.pan_Bottoms.Location = new Point(0, 0xd3);
            this.pan_Bottoms.Name = "pan_Bottoms";
            this.pan_Bottoms.Size = new Size(0x16f, 10);
            this.pan_Bottoms.TabIndex = 1;
            this.pane_TopT.Dock = DockStyle.Top;
            this.pane_TopT.Location = new Point(0, 0);
            this.pane_TopT.Name = "pane_TopT";
            this.pane_TopT.Size = new Size(0x16f, 10);
            this.pane_TopT.TabIndex = 0;
            this.pan_DockBottom.BackColor = Color.FromArgb(0xaf, 0xbf, 190);
            this.pan_DockBottom.Dock = DockStyle.Bottom;
            this.pan_DockBottom.Location = new Point(1, 0xdd);
            this.pan_DockBottom.Name = "pan_DockBottom";
            this.pan_DockBottom.Size = new Size(0x16f, 1);
            this.pan_DockBottom.TabIndex = 2;
            this.pan_DockRight.BackColor = Color.FromArgb(0xaf, 0xbf, 190);
            this.pan_DockRight.Dock = DockStyle.Right;
            this.pan_DockRight.Location = new Point(0x170, 0);
            this.pan_DockRight.Name = "pan_DockRight";
            this.pan_DockRight.Size = new Size(1, 0xde);
            this.pan_DockRight.TabIndex = 1;
            this.pan_Top.Controls.Add(this.pan_ZhongJian);
            this.pan_Top.Controls.Add(this.pan_TopRight);
            this.pan_Top.Controls.Add(this.pan_TopLeft);
            this.pan_Top.Dock = DockStyle.Top;
            this.pan_Top.Location = new Point(0, 0);
            this.pan_Top.Name = "pan_Top";
            this.pan_Top.Size = new Size(0x171, 0x20);
            this.pan_Top.TabIndex = 4;
            this.pan_ZhongJian.BackgroundImage = Resources.uc_title_2;
            this.pan_ZhongJian.Controls.Add(this.lblTitle);
            this.pan_ZhongJian.Dock = DockStyle.Fill;
            this.pan_ZhongJian.Location = new Point(0x1f, 0);
            this.pan_ZhongJian.Name = "pan_ZhongJian";
            this.pan_ZhongJian.Size = new Size(0x14d, 0x20);
            this.pan_ZhongJian.TabIndex = 2;
            this.lblTitle.AutoSize = true;
            this.lblTitle.BackColor = Color.FromArgb(0, 0, 15, 0xff);
            this.lblTitle.Font = new Font("宋体", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0x86);
            this.lblTitle.ForeColor = Color.FromArgb(0x3b, 0x56, 20);
            this.lblTitle.Location = new Point(6, 8);
            this.lblTitle.Name = "lblTitle";
            this.lblTitle.Size = new Size(0x77, 13);
            this.lblTitle.TabIndex = 0;
            this.lblTitle.Text = "采购茶叶操作流程";
            this.pan_TopRight.BackgroundImage = Resources.uc_title_1;
            this.pan_TopRight.Dock = DockStyle.Right;
            this.pan_TopRight.Location = new Point(0x16c, 0);
            this.pan_TopRight.Name = "pan_TopRight";
            this.pan_TopRight.Size = new Size(5, 0x20);
            this.pan_TopRight.TabIndex = 1;
            this.pan_TopLeft.BackgroundImage = Resources.uc_title;
            this.pan_TopLeft.Dock = DockStyle.Left;
            this.pan_TopLeft.Location = new Point(0, 0);
            this.pan_TopLeft.Name = "pan_TopLeft";
            this.pan_TopLeft.Size = new Size(0x1f, 0x20);
            this.pan_TopLeft.TabIndex = 0;
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x171, 0xfe);
            base.Controls.Add(this.pan_Dock);
            base.Controls.Add(this.pan_Top);
            base.FormBorderStyle = FormBorderStyle.None;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "FrmProLead";
            base.ShowInTaskbar = false;
            this.pan_Dock.ResumeLayout(false);
            this.pan_AllPanel.ResumeLayout(false);
            this.pan_AllPlanes.ResumeLayout(false);
            this.pan_AllPlanes.PerformLayout();
            this.panel_Button.ResumeLayout(false);
            this.panel2.ResumeLayout(false);
            this.panel2.PerformLayout();
            ((ISupportInitialize) this.pic_fukuan).EndInit();
            this.pan_采购.ResumeLayout(false);
            this.pan_采购.PerformLayout();
            ((ISupportInitialize) this.pic_caigou).EndInit();
            ((ISupportInitialize) this.pic_right).EndInit();
            this.pan_Top.ResumeLayout(false);
            this.pan_ZhongJian.ResumeLayout(false);
            this.pan_ZhongJian.PerformLayout();
            base.ResumeLayout(false);
        }

        private void link_caigou_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            FrmProcurementAdd add = new FrmProcurementAdd();
            if (add.ShowDialog() == DialogResult.OK)
            {
                this.pic_caigou.Enabled = false;
                this.link_caigou.Enabled = false;
                ProcurementEnt model = ProcurementBll.GetModel(this.newProId);
                if ((model != null) && (model.IsReview != 1))
                {
                    StockBll.InputDll(this.newProId.ToString());
                    model.IsReview = 1;
                    model.ReviewReason = "";
                    UserEnt loginUser = PublicAppliction.LoginUser;
                    model.ReviewMan = loginUser.UserId.ToString();
                    model.ReviewTime = DateTime.Now;
                    model.IsInput = 1;
                    ProcurementBll.FuCheck(model);
                    SupplierEnt ent3 = SupplierBll.GetModel(model.SupplierId);
                    ent3.CumulativeMoney += model.ToMeetMoney;
                    ent3.OutstMoney += model.ToMeetMoney;
                    ent3.PaidMoney = ent3.CumulativeMoney - ent3.OutstMoney;
                    SupplierBll.Update(ent3);
                }
            }
        }

        private void link_caigoufukuan_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
        }

        private void pan_TopLeft_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(base.Handle, 0x112, 0xf012, 0);
        }

        private void pan_ZhongJian_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(base.Handle, 0x112, 0xf012, 0);
        }

        private void panel_Button_Paint(object sender, PaintEventArgs e)
        {
            this.Panel_ResetPaint(e, this.panel_Button, Color.FromArgb(0xca, 0xc9, 0xce), 1, 1, 1, 1);
        }

        private void Panel_ResetPaint(PaintEventArgs e, Panel panel, Color color, int leftBoder, int topBoder, int rightBoder, int bottomBoder)
        {
            ControlPaint.DrawBorder(e.Graphics, panel.ClientRectangle, color, leftBoder, ButtonBorderStyle.Solid, color, topBoder, ButtonBorderStyle.Solid, color, rightBoder, ButtonBorderStyle.Solid, color, bottomBoder, ButtonBorderStyle.Solid);
        }

        private void pic_caigou_Click(object sender, EventArgs e)
        {
            FrmProcurementAdd add = new FrmProcurementAdd();
            if (add.ShowDialog() == DialogResult.OK)
            {
                this.pic_caigou.Enabled = false;
                this.link_caigou.Enabled = false;
                ProcurementEnt model = ProcurementBll.GetModel(this.newProId);
                if ((model != null) && (model.IsReview != 1))
                {
                    StockBll.InputDll(this.newProId.ToString());
                    model.IsReview = 1;
                    model.ReviewReason = "";
                    UserEnt loginUser = PublicAppliction.LoginUser;
                    model.ReviewMan = loginUser.UserId.ToString();
                    model.ReviewTime = DateTime.Now;
                    model.IsInput = 1;
                    ProcurementBll.FuCheck(model);
                    SupplierEnt ent3 = SupplierBll.GetModel(model.SupplierId);
                    ent3.CumulativeMoney += model.ToMeetMoney;
                    ent3.OutstMoney += model.ToMeetMoney;
                    ent3.PaidMoney = ent3.CumulativeMoney - ent3.OutstMoney;
                    SupplierBll.Update(ent3);
                }
            }
        }

        private void pic_fukuan_Click(object sender, EventArgs e)
        {
            FrmProcurementPaymentAdd add = new FrmProcurementPaymentAdd();
            if ((add.ShowDialog() == DialogResult.OK) && (add.newPayId.ToString() != ""))
            {
                UserEnt loginUser = PublicAppliction.LoginUser;
                ProcurementPaymentEnt model = ProcurementPaymentBll.GetModel(add.newPayId);
                model.IsCheck = 1;
                model.IsClear = 1;
                model.CheckMan = loginUser.UserId;
                model.CheckTime = DateTime.Now;
                ProcurementPaymentBll.Update(model);
                CompayAccountEnt ent3 = CompayAccountBll.GetModel(model.AccountId);
                if (model.AllMoney > ent3.AccountMoney)
                {
                    MessageBox.Show("抱歉帐户里余额不够无法支付!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                else
                {
                    ent3.AccountMoney -= model.AllMoney;
                    CompayAccountBll.Update(ent3);
                    CompayAccountDetailsEnt ent4 = new CompayAccountDetailsEnt {
                        CheckMan = loginUser.UserId,
                        CheckTime = DateTime.Now,
                        BuildMoney = model.AllMoney,
                        CreateMan = loginUser.UserId,
                        CreateTime = DateTime.Now,
                        DetailsType = 2,
                        InputDetailsSource = model.AccountId,
                        IsCheck = 1,
                        NotesNum = model.PuDocuNum,
                        Remark = model.Remark,
                        ChainNum = loginUser.ChainNum
                    };
                    CompayAccountDetailsBll.Add(ent4);
                    ent4.DetailsId = CompayAccountDetailsBll.GetMaxId("ChainNum=" + loginUser.ChainNum);
                    CompayAccountDetailsBll.Check(ent4);
                    SupplierEnt ent5 = SupplierBll.GetModel(model.SupplierId);
                    if (ent5 != null)
                    {
                        ent5.PaidMoney += model.AllMoney;
                        ent5.OutstMoney = ent5.CumulativeMoney - ent5.PaidMoney;
                        SupplierBll.Update(ent5);
                    }
                    DataTable list = ProcurementPaymentListBll.GetList("PurchaseId=" + model.PurchaseId);
                    foreach (DataRow row in list.Rows)
                    {
                        ProcurementEnt ent6 = ProcurementBll.GetModel(int.Parse(row["ProcurementId"].ToString()));
                        ent6.IsClearIngAll = 1;
                        ProcurementBll.Update(ent6);
                    }
                }
            }
        }

        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
    }
}

